﻿
function addMsg(obj, msg, css) {
    var thisObj = $(obj);
    thisObj.text(msg).removeClass().addClass(css);
}

//提示插件
jQuery.fn.extend({
    //出错信息
    addShowMsg: function (msg) {
        addMsg(this, msg, "sign_info");
    },
    //提示信息
    addInfoMsg: function (msg) {
        addMsg(this, msg, "tip_info");
    }
});

function ForgetPassword() {
    if ($.trim(mobile.val()).length == 0) {
        showInfo.addShowMsg("请输入手机号码！");
        return false;
    }
    if (mobile.val().search(/[1]+[3,5,8,4]+\d{9}$/) == -1) {
        showInfo.addShowMsg("手机号码格式不正确！");
        return false;
    }
    if (mobileCode.val().length == 0) {
        showInfo.addShowMsg("请输入手机验证码！");
        return false;
    }

    $.ajax({
        url: "/Ashx/Login/ForgetPasswordHandler.ashx",
        data: { action: "forgetPassword", mobile: encodeURIComponent(mobile.val()), mobileCode: encodeURIComponent(mobileCode.val()) },
        beforeSend: function () {
            showInfo.addInfoMsg("验证中...");
        },
        type: "POST",
        dataType: "json",
        success: function (result) {
            if (result.d== "true") {
                window.location.href = "http://user.daojutong.com/ForgetPassword1.aspx";
            }
            else {
                showInfo.addShowMsg(result.msg);
            }
        },
        error: function (httpRequest, textStatus, errorThrown) {
            showInfo.addShowMsg("系统出错，请重新登录！");
        }
    });
}

/*添加手机验证码*/
function GetMobileCode() {
    var mobile = $("#mobile").val();

    if (mobile.length <= 0) {
        alert("手机不能为空!");
        return;
    }
    if ($.trim(mobile).search(/[1]+[3,5,8,4]+\d{9}$/) == -1) {
        alert("手机号码格式不正确!");
        return;
    }
    $("#mobile").attr("readonly", "readonly");
    mu = setInterval(WaitInfo, 1000);
    var url = "http://user.daojutong.com/Ashx/Login/ForgetPasswordHandler.ashx";
    $.post(url, { action: "sendMsg", mobile: mobile }, function (result) {
        if (result.d == "true") {
            alert("发送成功!");
        }
        else {
            alert(result.msg);
        }
    }, "json");
}

var countNum = 120;
var mu;   //定时器对象
function WaitInfo() {
    if (countNum <= 0) {
        clearInterval(mu);
        countNum = 120;
        //换样式,并绑定事件
        $("#btnGetCode").attr("class", "yanzhen").bind("click", function () {
            GetMobileCode();
        }).html("获取验证码");
    }
    else {
        $("#btnGetCode").attr("class", "waitInfo").unbind("click").html(countNum + "秒后可以重新发送");
        countNum = countNum - 1;
    }
}

//定义
var showInfo;
var login;
var mobile;
var mobileCode;

$(function () {

    //初始化
    showInfo = $("#showInfo");
    login = $("#btnForgetPwd");
    mobile = $("#mobile");
    mobileCode = $("#mobileCode");

    login.click(function () {
        ForgetPassword();
    });
});